package com.tn.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * RefreshScope 刷新（获取实时）
 * @author tn
 * @version 1
 * @ClassName NacosTestController
 * @description 配置中心
 * @date 2020/8/5 21:36
 */
@RestController
@RequestMapping(value = "nacosConfig")
@RefreshScope
@Api(tags = "配置中心")
public class NacosConfigController {

    @Value("${server-user.testConstant}")
    private String testConstants;


    @Autowired
    private JdbcTemplate jdbcTemplate;


    /**
     *  nacos加载默认的配置文件
     */
    @ApiOperation(value = "配置中心 - test01")
    @GetMapping(value = "test01")
    public String test01() {
        return testConstants;
    }

    @GetMapping(value = "getUser")
    @ApiOperation(value = "配置中心 - getUser")
    public List<Map<String, Object>> getUser(){
        return jdbcTemplate.queryForList("select * from sys_user limit 1");
    }
}
